<?php
/**
 * Created by PhpStorm.
 * User: ttl
 * Date: 2019/5/24
 * Time: 21:34
 */

namespace app\common\validate;
use think\Validate;

class AddBuilds extends Validate
{
    protected $rule = [
        'names'  =>  'require|max:60|min:1',
        'icon' =>  'require|max:80|min:1',
        'build_type' =>  'require|check_build_type:',
        'remark'    => 'require|max:512|min:1',
        'contact_name'=>'max:50',
        'contact_phone'=>'max:16',
        'region_id'=>'require|check_region_id:',
        'address'=>'require|min:1|max:100'
    ];

    protected $message  =   [
        'names.require' => '名称必须',
        'names.min'     => '名称长度不能够小于1',
        'names.max'     => '名称最多不能超过60个字',
        'icon.require' => '请上传设施头像',
        'icon.min'     => '设施图像格式错误',
        'icon.max'     => '设施图像格式过长',
        'build_type.require'   => '请选择设施类型',
        'build_type.check_build_type'  => '请选择正确是设施类型',
        'remark.require'   => '请选择设施简介',
        'remark.min'  => '请填写一个字的简介',
        'remark.max'  => '最多512字的简介',
        'contact_name.require'   => '请您填写联系人',
        'contact_name.min'  => '联系人最少一个字',
        'contact_name.max'  => '联系人最多50字',
        'contact_phone.require'   => '请您填写联系人电话',
        'contact_phone.min'  => '电话格式有误.',
        'contact_phone.max'  => '电话格式有误..',
        'region_id.require'   => '请选择设施所在区域',
        'region_id.check_region_id'  => '请选择正确的区域',
        'address.require'   => '请填写设施地址',
        'address.min'  => '设施地址最少一个字.',
        'address.max'  => '设施地址最多100字..',
    ];
    /**
     * 类型检测
     * @param $value
     * @return bool
     */
    public function check_build_type($value){
        if($value<=0){
            return false;
        }
        return true;
    }

    /**
     * 区域检测
     * @param $value
     * @return bool
     */
    public function check_region_id($value){
        if($value<=0){
            return false;
        }
        return true;
    }
}